﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TTS;
using TTSBLL;
using TTSModel;
public partial class Repair_DM_DM_ALL : System.Web.UI.Page
{

    private string sn { get { return ViewState["sn"].ToString(); } set { ViewState["sn"] = value; } }
    private string message;
    private KCCSNUnion kccDelete;
    private const string storedProcedureName = "DMKCCSNUnion_delete";
    private const string storedProcedureName2358OR2046 = "DM2358OR2046_delete";
    private Assemble assemble_DM;
    private AssembleItem assembleItem_DM;
    protected void Page_Load(object sender, EventArgs e)
    {
        this.KCCSN_Text.Focus();
    }

    public Repair_DM_DM_ALL()
    {
        kccDelete = new KCCSNUnion();
        assemble_DM = new Assemble();
        assembleItem_DM = new AssembleItem();
    }
    protected void KCCSN_Text_TextChanged(object sender, EventArgs e)
    {

        sn = this.KCCSN_Text.Text.Trim();

        if (SNHelper.KccUpSNCheck(sn, out message))
        {
            if (!string.IsNullOrEmpty(kccDelete.KCCSNUnion_GetbyKCCSN1(sn).SN))
            {
                AssembleInfo ainfo = assemble_DM.Assemble_GetbySN(kccDelete.KCCSNUnion_GetbyKCCSN1(sn).SN);
                if (kccDelete.KCCSNUnion_GetbyKCCSN1(sn).SN.Substring(0, 8) == "T0002368")
                {
                    if (assembleItem_DM.AssembleItem_GetbyID(ainfo.ID).Count == 5)
                    {
                        this.Remove.Enabled = true;
                        this.Remove.Focus();
                    }
                    else
                    {
                        message = "请选择T0002368机箱组件解锁！";
                        ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
                        this.KCCSN_Text.Text = "";
                    }               
                }
                else
                {
                    this.Remove.Enabled = true;
                    this.Remove.Focus();
                }
                 
            }
            else
            {
                message = "该" + sn + "在数据库中无装配记录，请重新扫描正确的KCC！";
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
                this.KCCSN_Text.Text = "";
            }
        }
        else
        {
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
            this.KCCSN_Text.Text = "";
        }
    }
    protected void Repair_Click(object sender, EventArgs e)
    {
        if (kccDelete.KCCSNUnion_GetbyKCCSN1(sn).SN.Substring(0,8)=="T0002368")
        {
            kccDelete.KCCSNUnion_DeletebyKCCSN1(sn, storedProcedureName);
        }
        else
        {
            kccDelete.KCCSNUnion_DeletebyKCCSN1(sn, storedProcedureName2358OR2046);
        }
        message = "装配关系解锁成功！";
        ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
        this.KCCSN_Text.Text = "";
        this.Remove.Enabled = false;
    }
    protected void Return_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Repair/DM/DMRepairHtml.aspx");
    }
}